package com.example.gaojt.androiddemo.quickBoost;

import java.util.Random;

/**
 * Created by gaojt on 8/4/17.
 */

public class RandomUtil {
    static class InstanceHolder {
        final static Random instance = new Random();
    }

    public static int randInt(int n) {
        int sign = 1;
        if (n == 0) return 0;

        if (n < 0) {
            sign = -1;
            n = -n;
        }
        return InstanceHolder.instance.nextInt(n) * sign;
    }

    public static int randInt(int m, int n) {
        int base = n;
        int span = m - n;
        if (n > m) {
            base = m;
            span = n - m;
        }
        return base + randInt(span);
    }
}
